﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class smallclassmanage : System.Web.UI.Page
{
    public string sss = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"]==null)
		{
			Response.Write("<script language=javascript>alert('您没有管理权限或者还没有登录，请先登录！');window.open('../login.aspx','_top');</script>");
			Response.End();
		}
		if (!IsPostBack)
        {
            showbind();
        }
    }
    public void showbind()
    {

        DataSet dst = Socut.Data.ExecuteDataSet("select * from web_notice_bigclass order by bigclassorder");
        //string str = dst.Tables[0].Rows[0]["ks"].ToString();;
        //string[] strtype=str.Split(',');
        //dst.Clear();
        //sdatype.Dispose();

        //Response.Write(strtype);

        DataSet ds = Socut.Data.ExecuteDataSet("select * from web_notice_smallclass order by smallclassorder");

        string strbigclass = "";
        string strsmallclass = "";
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        foreach (DataRow dr1 in dst.Tables[0].Rows)
        {
            int count = 0;
            strbigclass = dr1["id"].ToString();
            sb.Append("<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#D7EBEC' class='dhlink'><tr><td colspan='6' height='30' bgcolor='#F4FCFF'><font color='#00527A'><b>" + dr1["bigclassname"] + "</font></b></td></tr><tr>");
            foreach (DataRow dr2 in ds.Tables[0].Rows)
            {
                strsmallclass = dr2["bigclassid"].ToString();
                if (check_ks(strbigclass.Split(','), strsmallclass))
                {
                    count++;
                    sb.Append("<td width=15% height=20 bgcolor='#ffffff'><input id='Ccheck' name='Ccheck' type='checkbox' style='border:0 ' value='"+dr2["id"]+"' /><a href='smallclassedit.aspx?id=" + dr2["id"] + "'>" + dr2["smallclassname"] + "</a></td>");
                    if (count % 6 == 0)
                    {

                        sb.Append("</tr><tr>");


                    }
                }
            }
            int aa = count % 6;
            for (int i = aa; i < 6; i++)
            {
                sb.Append("<td width=15% height=20 bgcolor='#ffffff'>&nbsp;</td>");
            }
            if (sb.ToString().EndsWith("<tr>"))
            {
                sb.Remove(sb.Length - 4, 4);

            }
            if (sb.ToString().EndsWith("</td>"))
            {
                sb.Append("</tr>");
            }
            sb.Append("</table>");
            sb.Append("<br>");
        }
        sss = sb.ToString();



    }
	
	    protected void Button1_Click(object sender, EventArgs e)
    {
        string ids = Request.Form["Ccheck"];
        if (string.IsNullOrEmpty(ids))
        {
            CommonFunction.ShowMessage("请选择要删除的项");
        }
        else
        {
            Socut.Data.ExecuteNonQuery("DELETE from web_Notice_smallclass where id in (" + ids + ")");
            CommonFunction.ShowMessage("删除成功","smallclassmanage.aspx");
        }
    }

	
	    private bool check_ks(string[] ksarry, string ksid)
    {
        for (int i = 0; i < ksarry.Length; i++)
        {
            if (ksarry[i] == ksid)
            {
                return true;
            }
        }
        return false;
    }
    public int IsNumeric(string str)
    {
        int i;
        if (str != null && System.Text.RegularExpressions.Regex.IsMatch(str, @"^-?\d+$") && str.Length < 7)
            i = int.Parse(str);
        else
            i = -1;
        return i;
    }

}
